package com.serialcommunication.communication;

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.bind.DatatypeConverter;

import com.serialcommunication.controller.Coordinator;

public class Reader implements Runnable {

	private InputStream dataInputStream;

	public Reader(InputStream inputStream) throws Exception {
		this.dataInputStream = inputStream;
	}

	public void run() {
		byte[] buffer = new byte[8];
		try {
			while (dataInputStream.available() > -1) {
				buffer = new byte[8];
				while (dataInputStream.available() !=  0) {
					System.out.println("Received ByteArray length: " + this.dataInputStream.read(buffer, 0, 8));
					Coordinator.newActionReceived(buffer);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
